﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public class LikesDataModel
    {
        HomestayWebDBEntities en = new HomestayWebDBEntities();
        public bool CheckUserLikePost(string username,int postID)
        {
            bool liked = false;
            List<Store_Like_CheckUserLikePost_Result> l = en.Store_Like_CheckUserLikePost(username, postID).ToList();
            if (l.Count > 0)
            {
                liked = true;
            }
            else
            {
                liked = false;
            }
            return liked;
        }
        public int CountLikeOfPost(int postID)
        {
            HomestayWebDBEntities en = new HomestayWebDBEntities();
            List<Store_Like_CountLikeOfPost_Result> l = en.Store_Like_CountLikeOfPost(postID).ToList();            
            int result = 0;
            result = Int32.Parse(l[0].NumberLikeOfPost.ToString());
            return result;
        }

        #region Hoangdx Code Like Function

        public void InsertLikePosts(int postID, string username)
        {
            Like LikeDB = new Like()
            {
                PostID = postID,
                Username = username,
                TimeCreated = DateTime.Now
            };
            en.Likes.AddObject(LikeDB);
            en.SaveChanges();
        }

        #endregion
    }
}
